#pragma once

#include <functional>

#include "eventloop_thread.h"
#include "noncopyable.h"

class EventLoopThreadPool : noncopyable{
public:
    using ThreadInitCallBack = std::function<void(EventLoop*)>; 

    EventLoopThreadPool(EventLoop* baseLoop, const std::string& nameArg);
    ~EventLoopThreadPool();

    void setThreadNum(int numThreads) {numThreads_ = numThreads;}
    void start(const ThreadInitCallBack&cb = ThreadInitCallBack());

    //如果工作在多线程中， baseLoop_ 默认以轮询的方式分配channel给subLoop
    EventLoop* getNextLoop();
    std::vector<EventLoop*> getAllLoops();

    bool started() const {return started_;}
    const std::string name() const{return name_;}
private:
    // baseLoop 是用户设置的
    EventLoop * baseLoop_;
    //
    std::string name_;
    bool started_;
    int numThreads_;
    int next_;
    std::vector<std::unique_ptr<EventLoopThread>> threads_;
    std::vector<EventLoop*> loops_;
};